class CommonUtil {
    static formatBytes(bytes, decimals) {
        if(bytes === 0) return '0 Byte';
        const k = 1024; // or 1000 for binary
        const dm = decimals + 1 || 3;
        const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
        const i = Math.floor(Math.log(bytes) / Math.log(k));
        return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
    }
    static formatTimeStr(timestamp) {
        const secNum = parseInt(timestamp, 10); // don't forget the second param
        const hours   = Math.floor(secNum / 3600);
        const minutes = Math.floor((secNum - (hours * 3600)) / 60);
        const seconds = secNum - (hours * 3600) - (minutes * 60);
        let timestr = '';
        if (hours > 0) {
            timestr += hours + '小时';
        }
        if (minutes > 0) {
            timestr += minutes + '分';
        }
        if (seconds > 0) {
            timestr += seconds + '秒';
        }
        return timestr;
    }
 }


export default CommonUtil;